//
//  HistoryInidentDetailController.m
//  Runone
//
//  Created by runone02 on 16/12/7.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "HistoryInidentDetailController.h"
#import "IncidentDetailCell.h"
#import "ROPointAnnotation.h"
#import "CustomAnnotationView.h"
#import "CustomCallOutView.h"
#import "RequestGinsengModel.h"
#import "RequestHelper.h"
#import "AppLocalManager.h"
#import "AppDelegate.h"
#import "MJRefresh.h"
#import "EventDetailModel.h"
#import "MJExtension.h"
#import "EventBaseInfoModel.h"
#import "EventDealListModel.h"
#import "SecetionHeaderView.h"
#import "CameraGunDetailViewController.h"
#import "RightCodeTool.h"
#import "EventPictureCell.h"
#import "EventCellFrame.h"
#import "SGImagePickerController.h"
#import "UIView+Addition.h"
#import "OneConst.h"
#import "CameraDetailController.h"
#import "OneConst.h"
#import "ROActionSheet.h"
#import "LittleVideoViewController.h"
#import "AppConstants.h"
#import "EnlargeMapViewController.h"
#import "HistoryIncidentHeaderView.h"

@interface HistoryInidentDetailController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) HistoryIncidentHeaderView *headerView;//头部

@property (nonatomic, strong) NSMutableArray *dataArray;

@property (nonatomic, strong)  EventDetailModel *deatilModel;

@property (nonatomic, strong) NSMutableArray *annotationsArray;


@property (assign, nonatomic) AllIconType type;

@property (nonatomic, strong) ROActionSheet *sheet;


@end

@implementation HistoryInidentDetailController

#pragma  ------------ 搜索界面   事故详情

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = YES;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _type             = AllIconTypeIncident;
    _annotationsArray = [[NSMutableArray alloc] init];
    _deatilModel      = [[EventDetailModel alloc] init];
    _dataArray        = [[NSMutableArray alloc] init];
    
    [self loadIncidentData];
    [self configNavigationbar]; // 导航栏
}

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden            = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden = YES;
    [_sheet hiddenSheet];
}

- (void) configNavigationbar {
#pragma mark - 屏蔽添加图片
//        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"camer_24.png"] style:UIBarButtonItemStylePlain target:self action:@selector(addPictureOrVideo)];
//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"相 册" style:UIBarButtonItemStylePlain target:self action:@selector(addPictureOrVideo)];
    self.view.backgroundColor=[UIColor whiteColor];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.size     = CGSizeMake(100, 30);
    titleLabel.text     = @"历史事件详情";
    titleLabel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = titleLabel;
}

//- (void) addPictureOrVideo {
//    NSLog(@"这个照相机哦");
//    _sheet = [[ROActionSheet alloc] initWithFrame:self.view.bounds titleArr:@[@"从手机相册选择", @"拍照"]];
//    __weak typeof(_sheet) weakSheet = _sheet;
//    __weak typeof(self) weakSelf = self;
//    _sheet.Click = ^(NSInteger clickIndex) {
//        switch (clickIndex) {
//            case 0:
//                //                [self UpLoadPictures];
//                break;
//            case 1:
//                NSLog(@"拍照");
//                break;
//            case 2:
//                NSLog(@"小视频");
//                LittleVideoViewController *vc = [[LittleVideoViewController alloc] init];
//                //                vc.delegate = weakSelf;
//                [weakSelf.navigationController presentViewController:vc animated:YES completion:nil];
//                break;
//        }
//        [weakSheet hiddenSheet];
//    };
//    [self.navigationController.view addSubview:weakSheet];
//}

- (void)loadIncidentData { //事故事件
    RequestHelper *requestHelper=[[RequestHelper alloc] init];
    RequestGinsengModel *GetAccidentEventDetailInfoModel=[[RequestGinsengModel alloc] init];
    GetAccidentEventDetailInfoModel.URL         = GetEventDataURL;
    GetAccidentEventDetailInfoModel.DataValue   = [self DataValueStr:self.CEModel.IncidentUID];
    GetAccidentEventDetailInfoModel.UpdatedTime = @"";
    GetAccidentEventDetailInfoModel.SystemCode  = @"GuangleHighway";
    GetAccidentEventDetailInfoModel.MethodName  = @"GetAccidentEventDetailInfo";
    requestHelper.block=^(RequestOutginseng *requestOutginseng,id dataValueModel){
        
        _deatilModel = [EventDetailModel mj_objectWithKeyValues:requestOutginseng.DataValue];
        
        for (EventDealListModel *dealModel in _deatilModel.EventDealList) {
            EventCellFrame *cellF = [[EventCellFrame alloc] init];
            cellF.lModel = dealModel;
            [_dataArray addObject:cellF];
        }
        [self configTableView];
        [self configHeaderView];
        _headerView.eventModel = _deatilModel;
        [self.tableView reloadData];
    };
    [requestHelper RequestGinsengModel:GetAccidentEventDetailInfoModel andPushController:self];
}

- (void) configTableView {
    self.tableView.contentInset   = UIEdgeInsetsMake(64, 0, 0, 0);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.bounces        = NO;
    self.tableView.delegate       = self;
    self.tableView.dataSource     = self;
    
}

- (void) configHeaderView {
    _headerView            = [[[NSBundle mainBundle] loadNibNamed:@"HistoryIncidentHeaderView" owner:self options:nil] lastObject];
    _headerView.frame      = CGRectMake(0, 0, self.view.bounds.size.width,356);
    _headerView.ceModel    = _CEModel;
    _headerView.eventModel = _deatilModel;
    [_headerView.enlargeBtn addTarget:self action:@selector(enlargeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    self.tableView.tableHeaderView = _headerView;
}

- (void) enlargeBtnClick {
    EnlargeMapViewController *vc = [[EnlargeMapViewController alloc] init];
    vc.la                        = [_CEModel.Latitude floatValue];
    vc.lo                        = [_CEModel.Longitude floatValue];
    vc.type                      = _type;
    [self presentViewController:vc animated:YES completion:nil];
}


#pragma mark - tableviewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    EventPictureCell *cell = [EventPictureCell cellWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    EventCellFrame *cellF = _dataArray[indexPath.row];
    cell.cellFrame = cellF;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    EventCellFrame *cellF =  _dataArray[indexPath.row] ;
    return cellF.cellH;
}

- (NSString *)DataValueStr:(NSString *)IncidentUID {
    NSString *valueStr =[NSString stringWithFormat:@"[{\"key\":\"EventUID\",\"value\":\"%@\"}]",IncidentUID];
    return valueStr;
}


@end
